﻿#region Namespace Inclusions
using System;
using System.Data;
using System.Text;
using System.Drawing;
using System.IO.Ports;
using System.Windows.Forms;
using System.ComponentModel;
using System.Collections.Generic;
using System.Threading;
using System.Timers;

using SCI_actuator.Properties;
#endregion

namespace SCI_actuator
{
    public partial class EEPROM_setting : Form
    {
        private menu_control frmain;
        private xmlrw scixml;
        public EEPROM_setting(menu_control fr)
        {
            InitializeComponent();
            this.frmain = fr;
            scixml = new xmlrw();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            byte[] bRx = this.frmain.HexStringToByteArray(scixml.Read_ServoID() + "03" + "03" + "00");
            byte sum = this.frmain.checksum(bRx);
            string senddata = "FF" + "FF" + scixml.Read_ServoID() + "03" + "03" + "00" + Convert.ToString(sum,16);
            if (this.frmain.send_timer.Enabled == true)
            {
                this.frmain.send_timer.Stop();
            }
            this.frmain.servosend(senddata);
            if (this.frmain.realtime_judge == false)
            {
                this.frmain.send_timer.Stop();
            }
            else if (this.frmain.realtime_judge == true)
            {
                this.frmain.send_timer.Start();
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            byte[] bRx = this.frmain.HexStringToByteArray(scixml.Read_ServoID() + "03" + "03" + "01");
            byte sum = this.frmain.checksum(bRx);
            string senddata = "FF" + "FF" + scixml.Read_ServoID() + "03" + "03" + "01" + Convert.ToString(sum, 16);
            if (this.frmain.send_timer.Enabled == true)
            {
                this.frmain.send_timer.Stop();
            }
            this.frmain.servosend(senddata);
            if (this.frmain.realtime_judge == false)
            {
                this.frmain.send_timer.Stop();
            }
            else if (this.frmain.realtime_judge == true)
            {
                this.frmain.send_timer.Start();
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            byte[] bRx = this.frmain.HexStringToByteArray(scixml.Read_ServoID() + "03" + "03" + "02");
            byte sum = this.frmain.checksum(bRx);
            string senddata = "FF" + "FF" + scixml.Read_ServoID() + "03" + "03" + "02" + Convert.ToString(sum, 16);
            if (this.frmain.send_timer.Enabled == true)
            {
                this.frmain.send_timer.Stop();
            }
            this.frmain.servosend(senddata);
            if (this.frmain.realtime_judge == false)
            {
                this.frmain.send_timer.Stop();
            }
            else if (this.frmain.realtime_judge == true)
            {
                this.frmain.send_timer.Start();
            }
        }

        private void button5_Click(object sender, EventArgs e)
        {
            byte[] bRx = this.frmain.HexStringToByteArray(scixml.Read_ServoID() + "03" + "03" + "03");
            byte sum = this.frmain.checksum(bRx);
            string senddata = "FF" + "FF" + scixml.Read_ServoID() + "03" + "03" + "03" + Convert.ToString(sum, 16);
            if (this.frmain.send_timer.Enabled == true)
            {
                this.frmain.send_timer.Stop();
            }
            this.frmain.servosend(senddata);
            if (this.frmain.realtime_judge == false)
            {
                this.frmain.send_timer.Stop();
            }
            else if (this.frmain.realtime_judge == true)
            {
                this.frmain.send_timer.Start();
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            this.Hide();
            this.Dispose();
        }
    }
}